import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Booking } from './booking.interface';
import { Model } from 'mongoose';
import { CreateBookingDTO, EditBookingDTO } from './booking.dto';

@Injectable()
export class BookingService {
    constructor(@InjectModel('booking') private readonly bookingModel: Model<Booking>)  {}

    async findAll(): Promise<Booking[]> {
        return await this.bookingModel.find();
    }

    async findWhere(filter?: object): Promise<Booking[]> {
        return await this.bookingModel.find(filter);
    }

    async find(id: string): Promise<Booking> {
        return await this.bookingModel.findById(id);
    }
    
    async addone(body: CreateBookingDTO): Promise<Booking> {
        return await this.bookingModel.create(body);
    }

    async editone(id: string, body: EditBookingDTO): Promise<Booking> {
        return await this.bookingModel.findByIdAndUpdate(id, body);
    }
    
    async delete(id: string): Promise<Booking> {
        return await this.bookingModel.findByIdAndDelete(id);
    }
}
